package com.woniuxy.ams.controller;

import com.woniuxy.ams.entity.AuditDetail;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.AuditDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dailyAuditDetail")
public class AuditDetailController {
    AuditDetailService auditDetailService;
    @Autowired(required = false)
    public void setAuditDetailService(AuditDetailService auditDetailService) {
        this.auditDetailService = auditDetailService;
    }

    /**
     * 新增日审核表
     */
    @RequestMapping("/insert")
    public ResultEntity<Integer> insertAuditDetail(@RequestBody AuditDetail auditDetail){
        int code = auditDetailService.insert(auditDetail);
        if (code!=0){
            return new ResultEntity<>(200,"新增日审核明细成功",code);
        }else{
            return new ResultEntity<>(400,"新增日审核明细失败",code);
        }
    }

    /**
     * 删除 日审核表
     */
    @RequestMapping("delete")
    public ResultEntity<Integer> deleteAuditDetail(@RequestBody AuditDetail auditDetail){
        int code = auditDetailService.delete(auditDetail);
        if (code!=0){
            return new ResultEntity<>(200,"删除日审核明细成功",code);
        }else{
            return new ResultEntity<>(400,"删除日审核明细失败",code);
        }
    }

    /**
     * 修改 日审核表
     */
    @RequestMapping("/update")
    public ResultEntity<Integer> updateAuditDetail(@RequestBody AuditDetail auditDetail){
        int code = auditDetailService.update(auditDetail);
        if (code!=0){
            return new ResultEntity<>(200,"修改日审核明细成功",code);
        }else{
            return new ResultEntity<>(400,"修改日审核明细失败",code);
        }
    }

    /**
     *按条件修改 日审核表
     */
    @RequestMapping("/updateConditional")
    public ResultEntity<Integer> updateConditional(@RequestBody AuditDetail auditDetail){
        int code = auditDetailService.conditionalModification(auditDetail);
        if (code!=0){
            return new ResultEntity<>(200,"修改日审核明细成功",code);
        }else{
            return new ResultEntity<>(400,"修改日审核明细失败",code);
        }
    }

    /**
     * 查询所有的 日审核表
     * @return
     */
    @RequestMapping("/findAll")
    public ResultEntity<List<AuditDetail>> findAllAuditDetail(){
        List<AuditDetail> all = auditDetailService.findAll();
        if (all!=null){
            return new ResultEntity<>(200,"查询所有成功",all);
        }else{
            return new ResultEntity<>(400,"查询失败,没有数据",null);
        }
    }

    /**
     * 根据id去查询一个 日审核详情
     * @param id
     * @return
     */
    @RequestMapping("/findOne")
    public ResultEntity<AuditDetail> findAuditDetail(@RequestParam("id") int id){
        AuditDetail auditDetail = auditDetailService.findById(id);
        if (auditDetail!=null){
            return new ResultEntity<>(200,"查询成功",auditDetail);
        }else{
            return new ResultEntity<>(400,"查询失败,没有数据",null);
        }
    }

    /**
     * 按条件查询！日审核详情
     */
    public ResultEntity<List<AuditDetail>> findConditional(@RequestBody AuditDetail auditDetail){
        List<AuditDetail> conditional = auditDetailService.findConditional(auditDetail);
        if (auditDetail!=null){
            return new ResultEntity<>(200,"查询成功",conditional);
        }else{
            return new ResultEntity<>(400,"查询失败,没有数据",null);
        }
    }

}
